#include <stdlib.h>
#include <stdio.h>

#include "bitboards.h"


/* deplacement et attaque des pawns */
static inline bitboard deplace_pawn_white1( bitboard x ) 
{
	return x<<8;
}
static inline bitboard deplace_pawn_white2( bitboard x ) 
{
	return x<<16;
}
static inline bitboard deplace_pawn_black1( bitboard x ) 
{
	return x>>8;
}
static inline bitboard deplace_pawn_black2( bitboard x ) 
{
	return x>>16;
}
static inline bitboard attack_pawn_white_r( bitboard x ) 
{
	return x<<9;
}
static inline bitboard attack_pawn_white_l( bitboard x ) 
{
	return x<<7;
}
static inline bitboard attack_pawn_black_r( bitboard x ) 
{
	return x>>9;
}
static inline bitboard attack_pawn_black_l( bitboard x ) 
{
	return x>>7;
}
/* deplacement et attaque des tours*/
static inline bitboard deplace_rook_r( bitboard x, size_t n ) 
{
	return x<<1*n;
}
static inline bitboard deplace_rook_l( bitboard x, size_t n ) 
{
	return x>>1*n;
}
static inline bitboard deplace_rook_b( bitboard x, size_t n ) 
{
	return x<<8*n;
}
static inline bitboard deplace_rook_f( bitboard x, size_t n ) 
{
	return x>>8*n;
}
/* deplacement et attaque des fous */
static inline bitboard deplace_bishop_br( bitboard x, size_t n ) 
{
	return x<<9*n;
}
static inline bitboard deplace_bishop_bl( bitboard x, size_t n ) 
{
	return x<<7*n;
}
static inline bitboard deplace_bishop_fr( bitboard x, size_t n ) 
{
	return x>>7*n;
}
static inline bitboard deplace_bishop_fl( bitboard x, size_t n ) 
{
	return x>>9*n;
}
/* deplacement et attaque des cavaliers */
static inline bitboard deplace_knight_br( bitboard x, size_t n ) 
{
	return x<<17*n;
}
static inline bitboard deplace_knight_bl( bitboard x, size_t n ) 
{
	return x<<15*n;
}
static inline bitboard deplace_knight_fr( bitboard x, size_t n ) 
{
	return x>>15*n;
}
static inline bitboard deplace_knight_fl( bitboard x, size_t n ) 
{
	return x>>17*n;
}
static inline bitboard deplace_knight_rb( bitboard x, size_t n ) 
{
	return x<<10*n;
}
static inline bitboard deplace_knight_lb( bitboard x, size_t n ) 
{
	return x<<6*n;
}
static inline bitboard deplace_knight_rf( bitboard x, size_t n ) 
{
	return x>>6*n;
}
static inline bitboard deplace_knight_lf( bitboard x, size_t n ) 
{
	return x>>10*n;
}
/* deplacement et attaque de la reine */
static inline bitboard deplace_queen_r( bitboard x, size_t n ) 
{
	return x<<1*n;
}
static inline bitboard deplace_queen_l( bitboard x, size_t n ) 
{
	return x>>1*n;
}
static inline bitboard deplace_queen_b( bitboard x, size_t n ) 
{
	return x<<8*n;
}
static inline bitboard deplace_queen_f( bitboard x, size_t n ) 
{
	return x>>8*n;
}
static inline bitboard deplace_queen_br( bitboard x, size_t n ) 
{
	return x<<9*n;
}
static inline bitboard deplace_queen_bl( bitboard x, size_t n ) 
{
	return x<<7*n;
}
static inline bitboard deplace_queen_fr( bitboard x, size_t n ) 
{
	return x>>7*n;
}
static inline bitboard deplace_queen_fl( bitboard x, size_t n ) 
{
	return x>>9*n;
}
/* deplacement et attaque du roi */
static inline bitboard deplace_king_l( bitboard x ) 
{
	return x<<1;
}
static inline bitboard deplace_king_r( bitboard x ) 
{
	return x>>1;
}
static inline bitboard deplace_king_b( bitboard x ) 
{
	return x<<8;
}
static inline bitboard deplace_king_f( bitboard x ) 
{
	return x>>8;
}
static inline bitboard deplace_king_br( bitboard x ) 
{
	return x<<9;
}
static inline bitboard deplace_king_bl( bitboard x ) 
{
	return x<<7;
}
static inline bitboard deplace_king_fr( bitboard x ) 
{
	return x>>7;
}
static inline bitboard deplace_king_fl( bitboard x ) 
{
	return x>>9;
}

bitboard to_black ( bitboard x)
{
    if (WHITE_P == x)
        return x<<40;
    return x<<56;
}

void print_ech (bitboard b)
{
    int i;
    bitboard mask = 1;
    for (i = 0; i < 64; i++)
    {
        if (i%8 == 0)
            printf("\n");
        if (i > 0)
            mask = mask<<1;

        if (mask & b)
            printf("1 ");
        else
            printf("0 ");
    }
    printf("\n"); 
}


int main ()
{
    bitboard b;
    b = WHITE_P;
    puts("pions");
    print_ech(b);
    b = to_black(b);
    print_ech(b);
    b = WHITE_T;
    puts("tours");
    print_ech(b);
    b = b << 56;
    puts("tours");
    print_ech(b);
    b = WHITE_B;
    puts("fous");
    print_ech(b);
    b = WHITE_C;
    puts("cavaliers");
    print_ech(b);
    b = WHITE_Q;
    puts("dame");
    print_ech(b);
    b = WHITE_K;
    puts("roi");
    print_ech(b);
	return 0;
}
